package sk.naive.talker.props;

import sk.naive.talker.util.PropertyConfiguration;

import java.util.*;
import java.io.Serializable;

/**
 * RemotePropertyConfiguration is created whe adapter is initialized and sent as a part
 * of adapter registration process to talker server.
 * 
 * @author <a href="mailto:virgo@naive.deepblue.sk">Richard "Virgo" Richter</a>
 * @version $Revision: 1.3 $ $Date: 2004/04/25 08:11:55 $
 */
public class RemotePropertyConfiguration implements Serializable {
	private Set<String> adapterSettable;
	private Set<String> adapterPersistent;
	private Map<String,Property> adapterProperties;

	private Set<String> userSettable;
	private Set<String> userPersistent;
	private Map<String,Property> userProperties;

	public RemotePropertyConfiguration(PropertyConfiguration adapterPropertyConfiguration, PropertyConfiguration userPropertyConfiguration) {
		adapterSettable = adapterPropertyConfiguration.getSettable();
		adapterPersistent = adapterPropertyConfiguration.getPersistent();
		userSettable = userPropertyConfiguration.getSettable();
		userPersistent = userPropertyConfiguration.getPersistent();
		adapterProperties = configureRemoteProperties(adapterPropertyConfiguration);
		userProperties = configureRemoteProperties(userPropertyConfiguration);
	}

	private Map<String,Property> configureRemoteProperties(PropertyConfiguration propertyConfiguration) {
		Map<String,Property> map = new HashMap<String,Property>();
		for (String propName : propertyConfiguration.getPropertyNames()) {
			if (propertyConfiguration.getSettable().contains(propName)
				|| propertyConfiguration.getPersistent().contains(propName))
			{
				Property prop = propertyConfiguration.getProperty(propName);
				map.put(propName, new RemoteProperty(prop.validValues(), prop.defaultValue()));
			}
		}
		return map;
	}

	public Set<String> getAdapterSettable() {
		return adapterSettable;
	}

	public Set<String> getAdapterPersistent() {
		return adapterPersistent;
	}

	public Map<String,Property> getAdapterProperties() {
		return adapterProperties;
	}

	public Set<String> getUserSettable() {
		return userSettable;
	}

	public Set<String> getUserPersistent() {
		return userPersistent;
	}

	public Map<String,Property> getUserProperties() {
		return userProperties;
	}
}
